#include "additem.h"
#include "ui_additem.h"

AddItem::AddItem(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AddItem)
{
    ui->setupUi(this);

    ui->keys->addItems(statement);
    ui->keys->setCurrentIndex(-1);
}

AddItem::~AddItem()
{
    delete ui;
}

void AddItem::setItem(const QString &key,const QString &value)
{
    ui->keys->setCurrentText(key);
    ui->value->setPlainText(value);
}

void AddItem::on_btn_submit_clicked()
{
    if(ui->keys->currentIndex() == -1)
        return;

    QString key=ui->keys->currentText();
    QString value=ui->value->toPlainText().trimmed();
    if(value.isEmpty())
        return;

    if(sp_containChinese(value))
    {
        QMessageBox::StandardButton result=
                QMessageBox::warning(this,"语句检测异常",
                                     "语句中检测到中文或是中文符号，是否继续？",
                                     QMessageBox::Ok | QMessageBox::Cancel,
                                     QMessageBox::Cancel);
        if(result == QMessageBox::Cancel)
            return;
    }
    emit addItem(key,value);
    accept();
}
